//
//  HomeTopGroupItem.swift
//  TimMusic
//
//  Created by nkl on 2024/10/10.
//

import Foundation
import UIKit

class HomeTopGroupItemView: UIControl {
    lazy var titleView: UIImageView = .simpleImage(imageName: "ic_favorite")
    lazy var titleLabel: UILabel = .simpleLabel(text: "0", font: .systemFont14, color: .white)
    lazy var bgImageView: UIImageView = .simpleImage(imageName: "ic_like_item")

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white.withAlphaComponent(0.1)
        layer.cornerRadius = 4
        layer.masksToBounds = true
        addChildren()
        makeConstraints()
    }

    func addChildren() {
        bgImageView.contentMode = .scaleAspectFit
        addSubview(titleLabel)
        addSubview(titleView)
        addSubview(bgImageView)
    }

    func makeConstraints() {
        titleView.snp.makeConstraints { make in
            make.leading.top.equalToSuperview().offset(12)
        }
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(titleView.snp.bottom).offset(12)
            make.leading.equalTo(titleView)
        }
        bgImageView.snp.makeConstraints { make in
            make.trailing.bottom.equalToSuperview()
            make.width.equalTo(80)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class HomeTopGroupRecentlyItemView: HomeTopGroupItemView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        bgImageView.image = UIImage(named: "ic_recently_item")
        titleView.image = UIImage(named: "ic_recently")
    }

    override func makeConstraints() {
        super.makeConstraints()
        bgImageView.snp.remakeConstraints { make in
            make.trailing.bottom.equalToSuperview()
            make.width.equalTo(40)
            make.height.equalTo(50)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class HomeTopGroupMostItemView: HomeTopGroupRecentlyItemView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        bgImageView.image = UIImage(named: "ic_most_item")
        titleView.image = UIImage(named: "ic_mostplay")
    }

    override func makeConstraints() {
        super.makeConstraints()
        bgImageView.snp.remakeConstraints { make in
            make.trailing.bottom.equalToSuperview()
            make.width.equalTo(50)
            make.height.equalTo(60)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
